package com.yami.shop.api.listener;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yami.shop.bean.event.ReproductionQrcodeEvent;
import com.yami.shop.bean.model.ReproductionQrcode;
import com.yami.shop.service.ReproductionQrcodeService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component("reproductionQrcodeListener")
@AllArgsConstructor
public class ReproductionQrcodeListener {

    @Autowired
    private ReproductionQrcodeService reproductionQrcodeService;

    /**
     * 二维码认证 修改
     * @param event
     */
    @EventListener(ReproductionQrcodeEvent.class)
    public void defaultSubmitOrderListener(ReproductionQrcodeEvent event) {
        // 只处理 认证的数据
        if(!"authentication".equals(event.getQrcodeType())){
            return;
        }
        // 修改认证状态
        ReproductionQrcode reproductionQrcode = reproductionQrcodeService.getOne(new QueryWrapper<ReproductionQrcode>().eq("qrcode_code", event.getQrcodeCode()));
        if(reproductionQrcode.getStatus().equals("1")){
            return;
        }
        reproductionQrcode.setStatus("1");
        reproductionQrcodeService.updateById(reproductionQrcode);
    }


}
